get_MissPair() {

  TFile *f = new TFile("/atlas/data18a/lailinxu/2012_8TeV/HZZ4l/Z4l/MissPair/mergedTree/mc12_tree.root");
  TTree *tr = (TTree*)f->Get("NOM");

  TFile *fout = new TFile("fit_Eta_Z4l.root", "RECREATE");
  //TPaveStats *st = new TPaveStats(0.6, 0.6, 0.9, 0.9);
  //st->SetOptStat(1111);
  //st->SetOptFit(111);
  gStyle->SetOptStat(1110);
  gStyle->SetOptFit(111);
  gStyle->SetStatW(0.20);
  gStyle->SetStatFontSize(0.04);

  TCanvas *c = new TCanvas("c", "c", 800, 600);

  int nbin = 600;
  double xlow = -3, xhigh=3;
  int nRebin = 40;
  double binSize = nRebin*(xhigh-xlow)/(double)nbin; 
  double xmin = -3, xmax = 3;
  char title[100];
  
  double me = 0.511e-3, mmu = 0.106;
  double pt1,pt2, pt3, pt4;
  double eta1, eta2, eta3, eta4;
  double phi1, phi2, phi3, phi4;
  int _4e, _4m, _2e2m, _2m2e, _4l;
  UInt_t RunNumber, EventNumber, mc_channel_number;
  double Z1Match, Z2Match;
  double Lep1Match, Lep2Match, Lep3Match, Lep4Match;

  double Z1Match_4e_total, Z1Match_2e2m_total, Z1Match_2m2e_total, Z1Match_4m_total;
  double Z2Match_4e_total, Z2Match_2e2m_total, Z2Match_2m2e_total, Z2Match_4m_total;
  double Z1Match_4e_miss, Z1Match_2e2m_miss, Z1Match_2m2e_miss, Z1Match_4m_miss;
  double Z2Match_4e_miss, Z2Match_2e2m_miss, Z2Match_2m2e_miss, Z2Match_4m_miss;
  double Lep1Match_total, Lep2Match_total, Lep3Match_total, Lep4Match_total;
  double Lep1Match_miss, Lep2Match_miss, Lep3Match_miss, Lep4Match_miss;

  FILE *fo = fopen("missing_pair_rate.txt", "w");

  tr->SetBranchAddress("Lep1Pt", &pt1); 
  tr->SetBranchAddress("Lep2Pt", &pt2); 
  tr->SetBranchAddress("Lep3Pt", &pt3); 
  tr->SetBranchAddress("Lep4Pt", &pt4); 

  tr->SetBranchAddress("Lep1Eta", &eta1); 
  tr->SetBranchAddress("Lep2Eta", &eta2); 
  tr->SetBranchAddress("Lep3Eta", &eta3); 
  tr->SetBranchAddress("Lep4Eta", &eta4); 

  tr->SetBranchAddress("Lep1Phi", &phi1); 
  tr->SetBranchAddress("Lep2Phi", &phi2); 
  tr->SetBranchAddress("Lep3Phi", &phi3); 
  tr->SetBranchAddress("Lep4Phi", &phi4); 

  tr->SetBranchAddress("FLAG_incl_MZ4l", &_4l);
  tr->SetBranchAddress("FLAG_eeee_MZ4l", &_4e);
  tr->SetBranchAddress("FLAG_eemm_MZ4l", &_2e2m);
  tr->SetBranchAddress("FLAG_mmee_MZ4l", &_2m2e);
  tr->SetBranchAddress("FLAG_mmmm_MZ4l", &_4m);

  tr->SetBranchAddress("mc_channel_number", &mc_channel_number);
  tr->SetBranchAddress("RunNumber", &RunNumber);
  tr->SetBranchAddress("EventNumber", &EventNumber);

  tr->SetBranchAddress("Z1Match", &Z1Match);
  tr->SetBranchAddress("Z2Match", &Z2Match);
  tr->SetBranchAddress("Lep1Match", &Lep1Match);
  tr->SetBranchAddress("Lep2Match", &Lep2Match);
  tr->SetBranchAddress("Lep3Match", &Lep3Match);
  tr->SetBranchAddress("Lep4Match", &Lep4Match);

  TLorentzVector l1, l2, l3, l4, lz1, lz2, lzz;

  int nevt = tr->GetEntries();
  cout << "events: " << nevt << endl;
  for( int i=0; i < nevt; i ++ ) {
	tr->GetEntry(i);
	double m1, m2;
	if(! _4l ) continue;
	if(_4e) { m1 = me; m2 = mmu; }
	if(_2e2m) { m1 = me; m2 = mmu; }
	if(_2m2e) { m1 = mmu; m2 = me; }
	if(_4m) { m1 = mmu; m2 = mmu; }

    //pt1 *= 1.002; pt2 *= 1.002; pt3 *= 1.002; pt4 *= 1.002;
	//if( pt2 <pt4 && pt4 < 10. || pt2 > pt4 && pt2 < 10. ) continue;
	//if( pt1 < 10. || pt3 < 10. ) continue;
	
    l1.SetPtEtaPhiM(pt1, eta1, phi1, m1);	
    l2.SetPtEtaPhiM(pt2, eta2, phi2, m1);	
    l3.SetPtEtaPhiM(pt3, eta3, phi3, m2);	
    l4.SetPtEtaPhiM(pt4, eta4, phi4, m2);	

    lz1 = l1 + l2; lz2 = l3 + l4;
	lzz = lz1 + lz2;
   
    double wt = 1.;
 
	double MZ1, MZ2, MZZ;
	MZ1 = lz1.M(); MZ2 = lz2.M(); MZZ = lzz.M();

    if(_4e) {
    	Z1Match_4e_total ++;
        if(Z1Match==2) Z1Match_4e_miss ++;
    	Z2Match_4e_total ++;
        if(Z2Match==2) Z2Match_4e_miss ++;
    } 
    if(_2e2m) {
    	Z1Match_2e2m_total ++;
        if(Z1Match==2) Z1Match_2e2m_miss ++;
    	Z2Match_2e2m_total ++;
        if(Z2Match==2) Z2Match_2e2m_miss ++;
    } 
    if(_2m2e) {
    	Z1Match_2m2e_total ++;
        if(Z1Match==2) Z1Match_2m2e_miss ++;
    	Z2Match_2m2e_total ++;
        if(Z2Match==2) Z2Match_2m2e_miss ++;
    } 
    if(_4m) {
    	Z1Match_4m_total ++;
        if(Z1Match==2) Z1Match_4m_miss ++;
    	Z2Match_4m_total ++;
        if(Z2Match==2) Z2Match_4m_miss ++;
    } 
    Lep1Match_total ++; Lep2Match_total ++; Lep3Match_total ++; Lep4Match_total ++;
    if(Lep1Match==2) Lep1Match_miss ++; 
    if(Lep2Match==2) Lep2Match_miss ++; 
    if(Lep3Match==2) Lep3Match_miss ++; 
    if(Lep4Match==2) Lep4Match_miss ++; 

  }

  fprintf(fo,"Lepton pair missing pariting\n");
  fprintf(fo, "%-10s%-10s%-15s%-15s%-10s%-15s%-15s\n", "Ch", "Z1 total", "Z1 misspair", "rate", "Z2 total", "Z2 misspair", "rate");
  fprintf(fo, "%-10s%-10.1f%-15.1f%-15.3f%-10.1f%-15.1f%-15.3f\n", "4e", Z1Match_4e_total, Z1Match_4e_miss, Z1Match_4e_miss/Z1Match_4e_total, Z2Match_4e_total, Z2Match_4e_miss, Z2Match_4e_miss/Z2Match_4e_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-15.3f%-10.1f%-15.1f%-15.3f\n", "2e2m", Z1Match_2e2m_total, Z1Match_2e2m_miss, Z1Match_2e2m_miss/Z1Match_2e2m_total, Z2Match_2e2m_total, Z2Match_2e2m_miss, Z2Match_2e2m_miss/Z2Match_2e2m_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-15.3f%-10.1f%-15.1f%-15.3f\n", "2m2e", Z1Match_2m2e_total, Z1Match_2m2e_miss, Z1Match_2m2e_miss/Z1Match_2m2e_total, Z2Match_2m2e_total, Z2Match_2m2e_miss, Z2Match_2m2e_miss/Z2Match_2m2e_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-15.3f%-10.1f%-15.1f%-15.3f\n", "4m", Z1Match_4m_total, Z1Match_4m_miss, Z1Match_4m_miss/Z1Match_4m_total, Z2Match_4m_total, Z2Match_4m_miss, Z2Match_4m_miss/Z2Match_4m_total);

  fprintf(fo,"\nLepton missing matching \n");
  fprintf(fo, "%-10s%-10s%-15s%-20s\n", "Lep", "total", "miss match", "rate");
  fprintf(fo, "%-10s%-10.1f%-15.1f%-20.3f\n", "Lep1", Lep1Match_total, Lep1Match_miss, Lep1Match_miss/Lep1Match_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-20.3f\n", "Lep2", Lep2Match_total, Lep2Match_miss, Lep2Match_miss/Lep2Match_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-20.3f\n", "Lep3", Lep3Match_total, Lep3Match_miss, Lep3Match_miss/Lep3Match_total);
  fprintf(fo, "%-10s%-10.1f%-15.1f%-20.3f\n", "Lep4", Lep4Match_total, Lep4Match_miss, Lep4Match_miss/Lep4Match_total);


  fout->Write();
  fout->Close();
  f->Close();
}
